import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/a.dart';
import 'package:finance_app/src/common/config.dart';
import 'package:finance_app/src/router_gen/router_gen_providers.dart';
import 'package:finance_app/src/widgets/common/red_dot_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';

class NotificationButton extends StatelessWidget {
  final double paddingRight;
  final String entryPoint;
  final Key iconKey;

  const NotificationButton(
      {Key key, this.paddingRight, this.entryPoint, this.iconKey})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(
        right: paddingRight ?? getDp(10),
      ),
      child: IconButton(
          icon:
              SvgPicture.asset(A.assetsImagesSettingNotification, key: iconKey),
          onPressed: () async{
            RProvider.myProvider.globalMap[ConfigKey.msgCountData] =
            Config.msgCount..notification = 0;
            await RProvider.myProvider.updateGlobalMap();
            FocusScope.of(context).requestFocus(FocusNode());
            Routes.navigateTo(RouterGenProviders.notificationPage, params: {});
          }),
    );
  }
}

class GlobalNotificationButton extends StatelessWidget {
  const GlobalNotificationButton({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Center(child: NotificationButton()),
        Positioned(
          top: getDp(10),
          right: getDp(14),
          child: Selector<RProvider, int>(
            builder: (BuildContext context, int value, Widget child) =>
                RedDotWidget(
              count: value,
            ),
            selector: (_, __) => Config.msgCount?.notification??1,
            shouldRebuild: (p, n) => p != n,
          ),
        )
      ],
    );
  }
}
